﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace RegexJson
{
    public partial class frmRegex : Form
    {
        public frmRegex()
        {
            InitializeComponent();
            foreach (Control c in this.Controls)
            {
                if (c is TextBox)
                {
                    c.KeyDown += new KeyEventHandler(allTextBox_KeyDown);
                    c.DoubleClick += new EventHandler(allTextBox_DoubleClick);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Regex reg = new Regex(textBox2.Text, RegexOptions.Compiled);
            MatchCollection matchC = reg.Matches(textBox1.Text);
            StringBuilder sb = new StringBuilder();
            foreach (Match mc in matchC)
            {
                sb.AppendLine(mc.Value );
                //, Environment.NewLine)
            }
            textBox3.Text =sb.ToString();
            //textBox3.Text = reg.Replace(textBox1.Text, "");
        }



        /* 按下 Ctrl+A 全選文字 */
        private void allTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
                ((TextBox)sender).SelectAll();
        }

        /* 雙擊全選文字 */
        private void allTextBox_DoubleClick(object sender, EventArgs e)
        {
            ((TextBox)sender).SelectAll();
        }
    }
}
